using LegoBotPrimaAbstractions;
using LegoBotPrimaAbstractions.Unity;
using LegoBotPrimaUI;
using Microsoft.Practices.Unity;

namespace LegoBotPrima
{
    public class LegoBotFactory : UnityExtender<ILegoBotFactory>, ILegoBotFactory
    {
        public const string ContainerName = "LegoBotPrima";
        public static readonly ILegoBotFactory Get = Init(new LegoBotFactory());


        void IUnityExtender.RegisterTypes(IUnityContainer container)
        {
            container.RegisterInstance<ILegoBotFactory>(this, Singleton);
            container.RegisterType<ILegoBotPrimaWorkflow, LegoBotPrimaWorkflow>(Singleton);
            container.RegisterType<ILegoBotPrimaService, LegoBotPrimaService>(Singleton);
            container.RegisterType<ILegoBotPrimaConfig, Config>(Singleton);
            container.RegisterType<IWorkflowLogger, WorkflowLogger>(Singleton);
            container.RegisterType<IBotActionController, BotActionController>(Singleton);
            // non singletons
            container.RegisterType<IMainPrimaWindow, MainPrimaWindow>();
        }

        protected override string[] GetUnityConfigBlockNames()
        {
            return new[] { ContainerName };
        }

        #region implementing ILegoBotFactory
        public ILegoBotFactory Factory { get { return Container.Resolve<ILegoBotFactory>(); } }
        public ILegoBotPrimaWorkflow Workflow { get { return Container.Resolve<ILegoBotPrimaWorkflow>(); } }
        public ILegoBotPrimaService Service { get { return Container.Resolve<ILegoBotPrimaService>(); } }
        public ILegoBotPrimaConfig Config { get { return Container.Resolve<ILegoBotPrimaConfig>(); } }
        public IWorkflowLogger WorkflowLogger { get { return Container.Resolve<IWorkflowLogger>(); } }
        public IMainPrimaWindow MainWindow { get { return Container.Resolve<IMainPrimaWindow>(); } }
        public IBotActionController BotActionController { get { return Container.Resolve<IBotActionController>(); } }
        #endregion
    }
}